#version 330
in vec3 vertices;
in vec3 normals;
in vec4 tangents;
in vec2 vertexTexCoord;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix;

out vec3 coords;
out vec2 texCoord;
out mat3 tangentMatrix;
out float zPos;

void main() {
    texCoord = vertexTexCoord;
    vec4 position = viewMatrix * vec4(vertices,1.0);
    coords = position.xyz/position.w;
    vec3 normal = normalMatrix * normals.xyz;
    vec3 tangent = normalMatrix * tangents.xyz;

    vec3 binormal = normalize(cross(normal,tangent));
    tangentMatrix = mat3 (
        tangent.x, binormal.x, normal.x,
        tangent.y, binormal.y, normal.y,
        tangent.z, binormal.z, normal.z);

    vec4 screenPosition = projectionMatrix * position;
    gl_Position = screenPosition;
    zPos = screenPosition.z;
}
